package com.power.sifa.correction.model;


import cn.hutool.core.util.ObjectUtil;
import com.aventrix.jnanoid.jnanoid.NanoIdUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.plf.core.common.domain.BaseModel;
import com.power.sifa.correction.model.enumeration.St_work;
import com.power.sifa.correction.model.enumeration.Tp_crc_work;
import com.power.sifa.correction.model.pojo.bo.Crc_departBO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
*  预警处置任务实体类
*/

@Entity
@ApiModel(value="预警处置任务")
@Data
@Table(name="Cre_work",schema="sfapprove")
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
//@IdClass(Cre_work.Cre_workPK.class) 用于复合组件
public class Cre_work extends BaseModel implements Serializable {

	private static final long serialVersionUID = 1L;

    @Id
    @Setter(AccessLevel.NONE)
    @ApiModelProperty(value = "序号")
    private String id;

    @ApiModelProperty(value = "预警id")
    private String warnid;

    @ApiModelProperty(value = "处置类型")
    private Integer worktype = Tp_crc_work.UNDO;

    @ApiModelProperty(value = "单位id")
    private String deptid;

    @ApiModelProperty(value = "单位名称")
    private String deptname;

    @ApiModelProperty(value = "处置人id")
    private String userid;

    @ApiModelProperty(value = "处置人名称")
    private String username;

    @ApiModelProperty(value = "处置意见")
    private String remark;

    @ApiModelProperty(value = "状态")
    private Integer status = St_work.UNDO;

    @ApiModelProperty(value = "任务开始时间", example="2020-10-22 10:03:22")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createtime;

    @ApiModelProperty(value = "任务办结时间", example="2020-10-22 10:03:22")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date exectime;

    @ApiModelProperty(value = "督办id")
    private String supid;

    @ApiModelProperty(value = "再办id")
    private String repeatid;

    @ApiModelProperty(value = "ding待办id")
    private String todoid;

    /**
     * 行政复议录入人
     */
    @Transient
    private String regusername;

    /**
     * 预警类型
     */
    @Transient
    private String type;

    /**
     * 社矫人员id
     */
    @Transient
    private String perid;

    /**
     * 社矫姓名
     */
    @Transient
    private String pername;

    /**
     * 预警时间
     */
    @Transient
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date rectime;

    /**
     * 拍摄纬度
     */
    @Transient
    private String latcamera;

    /**
     * 拍摄经度
     */
    @Transient
    private String lngcamera;

    /**
     * 预警地点
     */
    @Transient
    private String addr;

    /**
     * 罪名
     */
    @Transient
    private String crime;

    /**
     * 是否督办
     */
    @Transient
    private String issup;

    /**
     * 是否再办
     */
    @Transient
    private String isrepeat;


    public Cre_work(Cre_warning cre_warning, Crc_departBO depart) {
        this.id = NanoIdUtils.randomNanoId();
        this.warnid = cre_warning.getId();
        this.worktype = Tp_crc_work.UNDO;
        if (ObjectUtil.isNotNull(depart)) {
            this.deptid = depart.getDepartid();
            this.deptname = depart.getOrgname();
            this.userid = depart.getUserid();
            this.username = depart.getUsername();
        }
        this.status = St_work.UNDO;
        this.createtime = new Date();
    }

    public Map<String, Object> parseMap() {
        Map<String, Object> map=new HashMap<>();
        map.put("id", this.getId());
        map.put("warnid", this.getWarnid());
        map.put("worktype", this.getWorktype());
        map.put("deptid", this.getDeptid());
        map.put("deptname", this.getDeptname());
        map.put("userid", this.getUserid());
        map.put("username", this.getUsername());
        map.put("remark", this.getRemark());
        map.put("status", this.getStatus());
        map.put("createtime", this.getCreatetime());
        map.put("exectime", this.getExectime());
        map.put("supid", this.getSupid());
        map.put("repeatid", this.getRepeatid());
        return map;
    }

    public String getId() {
        return id;
    }

    public void setId(Serializable id) {
        this.id = (String) id;
    }

    public Serializable getPrimaryKey() {
        return id;
        // return new Cre_workPK(id, id2); 用于复合主键，请手动创建内部静态类
    }

    public void setPrimaryKey(Serializable key) {
        this.id = (String)key;

        //Cre_workPK pk = (Cre_workPK) key; 用于复合主键
        //this.id = pk.getId();
        //this.id2 = pk.getId2();
    }

}
